// curry :: ((a, b, ...) -> c) -> a -> b -> ... -> c
function curry(fn) {
  return function $curry(...args) {
    if (args.length < fn.length) {
      return $curry.bind(null, ...args)
    } else {
      return fn.call(null, ...args)
    }
  }
}

function curry2(fn) {
  return function (a) {
    return function (b) {
      return fn(a, b)
    }
  }
}

// test

function add(a, b) {
  return a + b
}

let f = curry(add);
console.dir(f(1, 3))
